#include "device.h"

#include <iostream>
using std::cout;
using std::endl;

void all_info();

void show_info(std::shared_ptr<device::sBiosInfo> &info);
void show_info(std::shared_ptr<device::sBoardInfo> &info);
void show_info(std::shared_ptr<device::sChassisInfo> &info);
void show_info(std::shared_ptr<device::sSystemInfo> &info);
void show_info(std::shared_ptr<std::vector<device::sCpuInfo>> &info);
void show_info(std::shared_ptr<std::vector<device::sMemoryInfo>> &info);
void show_info(std::shared_ptr<std::vector<device::sConnectorInfo>> &info);
void show_info(std::shared_ptr<std::vector<device::sDiskInfo>> &info);

int main(int argc, char **argv) {
  all_info();
  return 0;
}

void all_info() {
  cout << "--------------------" << endl;
  auto info = device::get_info();
  show_info(info.bios);
  show_info(info.board);
  show_info(info.chassis);
  show_info(info.system);
  show_info(info.cpus);
  show_info(info.memorys);
  show_info(info.connectors);
  show_info(info.disks);
  cout << "--------------------" << endl;
}

void show_info(std::shared_ptr<device::sBiosInfo> &info) {
  if (!info) return;

  cout << "----- bios -----" << endl;
  cout << "Vendor: " << info->vendor << endl;
  cout << "Version: " << info->version << endl;
}
void show_info(std::shared_ptr<device::sBoardInfo> &info) {
  if (!info) return;

  cout << "----- board -----" << endl;
  cout << "Manufacturer: " << info->manufacturer << endl;
  cout << "Product: " << info->product << endl;
  cout << "Version: " << info->version << endl;
  cout << "Serial: " << info->serial << endl;
}
void show_info(std::shared_ptr<device::sChassisInfo> &info) {
  if (!info) return;

  cout << "----- chassis -----" << endl;
  cout << "Manufacturer: " << info->manufacturer << endl;
  cout << "Version: " << info->version << endl;
  cout << "Serial: " << info->serial << endl;
  cout << "Type: " << info->type << endl;
  cout << "SKU Number: " << info->sku_number << endl;
}
void show_info(std::shared_ptr<device::sSystemInfo> &info) {
  if (!info) return;

  cout << "----- system -----" << endl;
  cout << "Manufacturer: " << info->manufacturer << endl;
  cout << "Product: " << info->product << endl;
  cout << "Version: " << info->version << endl;
  cout << "Serial: " << info->serial << endl;
  cout << "UUID: " << info->uuid << endl;
  cout << "Wake Up Type: " << info->wake_up_type << endl;
  cout << "SKU Number: " << info->sku_number << endl;
  cout << "Family: " << info->family << endl;
}
void show_info(std::shared_ptr<std::vector<device::sCpuInfo>> &arr) {
  if (!arr) return;

  for (auto it = arr->begin(); it != arr->end(); ++it) {
    cout << "----- cpu " << (it - arr->begin()) << " -----" << endl;
    cout << "Manufacturer: " << it->manufacturer << endl;
    cout << "Product: " << it->product << endl;
    cout << "Serial: " << it->serial << endl;
    cout << "Type: " << it->type << endl;
    cout << "Family: " << it->family << endl;
    cout << "Core Count: " << it->core_count << endl;
    cout << "Core Enabled: " << it->core_enabled << endl;
    cout << "Thread Count: " << it->thread_count << endl;
  }
}
void show_info(std::shared_ptr<std::vector<device::sMemoryInfo>> &arr) {
  if (!arr) return;

  for (auto it = arr->begin(); it != arr->end(); ++it) {
    cout << "----- memory " << (it - arr->begin()) << " -----" << endl;
    cout << "Manufacturer: " << it->manufacturer << endl;
    cout << "Serial: " << it->serial << endl;
    cout << "Size: " << it->size << endl;
    cout << "Type: " << it->type << endl;
    cout << "Type Detail: " << it->type_detail << endl;
  }
}
void show_info(std::shared_ptr<std::vector<device::sConnectorInfo>> &arr) {
  if (!arr) return;
  
  for (auto it = arr->begin(); it != arr->end(); ++it) {
    cout << "----- connector " << (it - arr->begin()) << " -----" << endl;
    cout << "Internal Designator: " << it->internal_designator << endl;
    cout << "Internal Type: " << it->internal_type << endl;
    cout << "External Designator: " << it->external_designator << endl;
    cout << "External Type: " << it->external_type << endl;
    cout << "Port Type: " << it->port_type << endl;
  }
}
void show_info(std::shared_ptr<std::vector<device::sDiskInfo>> &arr) {
  if (!arr) return;
  
  for (auto it = arr->begin(); it != arr->end(); ++it) {
    cout << "----- disk " << (it - arr->begin()) << " -----" << endl;
    cout << "Dev Name: " << it->devname << endl;
    cout << "Manufacturer: " << it->manufacturer << endl;
    cout << "Product: " << it->product << endl;
    cout << "Serial Number: " << it->serial << endl;
    cout << "Sectors: " << it->sectors << endl;
    cout << "Sector Size: " << it->size / it->sectors << endl;
    cout << "All Size: " << it->size << " (";
    if (it->size / 1024.0 / 1024.0 / 1024.0 / 1024.0 > 1.0) {
      cout << it->size / 1024.0 / 1024.0 / 1024.0 / 1024.0 << "TB)" << endl;
    } else if (it->size / 1024.0 / 1024.0 / 1024.0 > 1.0) {
      cout << it->size / 1024.0 / 1024.0 / 1024.0 << "GB)" << endl;
    } else {
      cout << it->size / 1024.0 / 1024.0 << "MB)" << endl;
    }
  }
}